/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Pojo.Sach;
import Util.MySqlDataAccessHelper;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author USER
 */
public class SachDAO {

    public static List<Sach> danhMoiNhats() {
        List<Sach> kq = new ArrayList<Sach>();
        try {
            String sql = "SELECT * FROM sach ORDER BY ngay_nhap desc";
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while (rs.next()) {
                Sach s = new Sach();
                s.setMaSach(rs.getInt("ma_sach"));
                s.setTenSach(rs.getString("ten_sach"));
                s.setTacGia(rs.getString("tac_gia"));
                s.setHinhBia(rs.getString("hinh_bia"));
                s.setHinhChiTiet(rs.getString("hinh_chi_tiet"));
                s.setMaNhaXuatBan(rs.getInt("ma_nha_xuat_ban"));
                s.setMaTheLoai(rs.getInt("ma_the_loai"));
                s.setSoLuong(rs.getInt("so_luong"));
                s.setGiaNhap(rs.getFloat("gia_nhap"));
                kq.add(s);
            }
            helper.close();
        } catch (Exception e) {
        }
        return kq;

    }
}
